// pages/home/home.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    id: 0,
    LISTID: 3,
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg'
    ],
    arr: [{
      title: '美妆大咖',
      listID: 3
      },
      {
        title: '食品饮料',
        listID: 10
      },
      {
        title: '内衣袜子',
        listID: 16
      },
      {
        title: '精品个护',
        listID: 15
      },
      {
        title: '家居生活',
        listID: 7
      },
      {
        title: '数码科技',
        listID: 12
      },
      {
        title: '文体娱乐',
        listID: 11
      },
      {
        title: '时尚装备',
        listID: 4
      }],
    dataList: [],
    pingList: [],
    height: ''
  },
  reLoadDataList(e) {
    var index = e.currentTarget.dataset['index']
    var listID = e.currentTarget.dataset['listid']
    this.setData({
      active: index,
      LISTID: listID,
      dataList: []
    })
    this.loadDataList(0, this.data.LISTID)
  },
  loadPingList(size) {
    size = size || 0
    wx.request({
      url: 'http://www.xiongmaoyouxuan.com/api/tab/1?start='+size,
      data: '',
      header: {},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (res) => {
        if (res.data.code === 200 && res.statusCode === 200) {
          console.log(res)
          this.setData({
            imgUrls: this.data.pingList.concat(res.data.data.banners),
            pingList: this.data.pingList.concat(
              res.data.data.items.list.filter(item => {
                return item.title
              })
            )
          })
        }
      },
      fail: function(res) {
        console.log(res)
      },
      complete: function(res) {
      },
    })
  },
  loadDataList(size, id) {
    size = (size || 0) * 30
    id = id || this.data.LISTID
    console.log(id)
    wx.request({
      url: 'http://www.xiongmaoyouxuan.com/api/tab/' + id + '?start=' + size,
      data: '',
      header: {},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (res) => {
        if (res.data.code === 200 && res.statusCode === 200) {
          this.setData({
            dataList: this.data.dataList.concat(
              res.data.data.items.list.filter(item => {
                return item.title
              })
            )
          })
        }
      },
      fail: function(res) {
        console.log(res)
      },
      complete: function(res) {
      },
    })
  },
  lower() {
    console.log(11)
    let size = 2
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      success: () => {
      },
      complete: () => {
        this.loadDataList(size, this.data.LISTID)
      }
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.loadDataList()
    this.loadPingList()
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          height: res.windowHeight
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})